package com.tools.cleanmaster.ui.activity;

import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.tools.cleanmaster.R;
import com.tools.cleanmaster.model.item.TrashItem;
import com.tools.cleanmaster.ui.base.SingleActivity;
import com.tools.cleanmaster.ui.dialog.CommonDialog;
import com.tools.cleanmaster.utils.StringUtils;

import java.util.List;

/**
 * desc: 提供了一个确认删除的Dialog
 * date: 2018/7/4 11:40
 * author: ancun
 */
public abstract class DeepActivity extends SingleActivity {
    private CommonDialog mDeleteCommonDialog;
    private TextView mCountText;
    private TextView mSizeText;

    protected int mDeleteItemCount;
    protected long mDeleteItemSize;

    /**
     * 显示警示弹窗
     */
    protected void showDeleteDialog(DialogInfo info) {
        if (mDeleteCommonDialog == null) {
            mDeleteCommonDialog = new CommonDialog(DeepActivity.this);
            View v = LayoutInflater.from(DeepActivity.this).inflate(R.layout.common_delete_dialog, null);
            mDeleteCommonDialog.setContentView(v);
            mCountText = v.findViewById(R.id.count);
            mSizeText = v.findViewById(R.id.relese_space);
        }
        mDeleteCommonDialog.setTitle(R.string.app_clean_dialog_title_confirm);
        mDeleteCommonDialog.setCancelBtn(R.string.common_cancel, null);
        mDeleteCommonDialog.setOkBtn(R.string.app_clean_dialog_delete, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onDelete();
            }
        });
        mDeleteCommonDialog.setOkBtnDeleteBackground();
        mCountText.setText(Html.fromHtml(getString(R.string.trash_selected_file, info.count)));
        mSizeText.setText(Html.fromHtml(getString(R.string.trash_release_space, StringUtils.getSizeString(info.size))));
        mDeleteCommonDialog.show();
    }

    public static class DialogInfo {
        private String count;
        private long size;

        protected DialogInfo setCount(String count) {
            this.count = count;
            return this;
        }

        protected DialogInfo setSize(long size) {
            this.size = size;
            return this;
        }
    }

    protected void setDeleteButton(Button button) {
        if (mDeleteItemCount > 0) {
            button.setText(Html.fromHtml(getString(R.string.trash_image_clean,
                    StringUtils.getSizeString(mDeleteItemSize))));
            button.setEnabled(true);
        } else {
            button.setEnabled(false);
            button.setText(Html.fromHtml(getString(R.string.trash_image_clean, "")));
        }
    }

    /**
     * 上报展示次数
     *
     * @param key
     */
    protected void reportShow(String key) {

    }

    /**
     * 上报点击次数
     *
     * @param key
     */
    protected void reportClick(String key) {

    }

    private void reportDeleteDialog(String key) {

    }

    protected abstract void onDelete();

    protected abstract void delete(List<TrashItem> items);
}
